﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using EuroManager.Domain.Simulator.Engine;
using EuroManager.Domain.Simulator.Helpers;
using EuroManager.Domain.Simulator.Tactics;
using EuroManager.Domain.Simulator.World;
using NUnit.Framework;

namespace EuroManager.Domain.Simulator.Tests.Tactics
{
    [TestFixture]
    public class PlayerTacticsTests
    {
        [Test]
        public void ShouldCalculateTacticalLocation()
        {
            Pitch pitch = new Pitch();
            PitchSide side = PitchSide.Right;
            PlayerTactics tactics = new PlayerTactics(0.25f, 0.25f);
            tactics.Assign(1, 1, 0.20f, 0.2f);
            tactics.Assign(2, 1, 0.30f, 0.2f);
            tactics.Assign(1, 2, 0.15f, 0.4f);
            tactics.Assign(2, 2, 0.25f, 0.4f);

            Vector2D ballLocation = new Vector2D(1.2f * PlayerTactics.ZoneWidth, 1.3f * PlayerTactics.ZoneHeight);
            Vector2D location = tactics.CalculateTacticalLocation(pitch, side, pitch.MapToMetricalLocation(side, ballLocation));

            Vector2D proportionalLocation = pitch.MapToProportionalLocation(side, location);

            Assert.IsTrue(Vector2D.Equals(new Vector2D(0.205f, 0.26f), proportionalLocation, Maths.Epsilon));
        }

        [Test]
        public void ShouldCalculateKickOffLocation()
        {
            Pitch pitch = new Pitch();
            PitchSide side = PitchSide.Right;

            Vector2D desiredLocation = new Vector2D(0.45f, 0.12f);
            PlayerTactics tactics = new PlayerTactics(desiredLocation.X, desiredLocation.Y);
            Vector2D location = tactics.CalculateKickOffLocation(pitch, side);

            Vector2D proportionalLocation = pitch.MapToProportionalLocation(side, location);

            Assert.IsTrue(Vector2D.Equals(desiredLocation, proportionalLocation, Maths.Epsilon));
        }
    }
}
